<base href="<?php echo base_url();?>" />
<link rel="stylesheet" href="assets/style.css" type="text/css" media="screen"/>

<?php
   $size = sizeof($faecher);
   $varfach = "'Alle'";
   for($i=0; $i<$size; $i++) 
   {
   		$varfach = $varfach.", '".$faecher[$i]['Code']."'";
   }
   $kurssize = sizeof($kurse);
   $varkurs = "'Alle'";
   for($i=0; $i<$kurssize; $i++) 
   {
   		$varkurs = $varkurs.", '".$kurse[$i]['Code']."'";
   }
   echo '<h1>Gefiltert auf:</h1>';
   echo '<h2>Fach:'.$selectedfach.' und Kurs:'.$selectedkurs.'</h2>'
?>

<script type="text/javascript">
var faecher = Array(<?php echo $varfach ?>);
var kurse = Array(<?php echo $varkurs ?>)
//var faecher = Array('Alle','Deutsch','Englisch','Mathe');

function setFach(fachID,kurs) {	
	var fach = faecher[fachID];
	var fachurl = "index.php/klausuren_controller/klausurenlistview/0/" + fach + "/" + kurs;
	window.location.href = fachurl;
}
function setKurs(kursID,fach) {	
	var kurs = kurse[kursID];
	var kursurl = "index.php/klausuren_controller/klausurenlistview/0/" + fach + "/" + kurs;
	window.location.href = kursurl;
}
</script>

<label for="Fach">Fachfilter: </label>
	<select onchange="setFach(this.selectedIndex,'<?php echo $selectedkurs ?>')">
		<?php
		if($selectedfach == 'Alle')
		{
			echo '<option value="Alle" selected>Alle</option>';
		}
		else 
		{
			echo '<option value="Alle">Alle</option>';
		}
		
		foreach ($faecher as $fach){
			if($selectedfach == $fach['Code'])
			{
				echo '<option value='.$fach['Code'].' selected >'.$fach['Code'].'</option>';
			}
			else 
			{
				echo '<option value='.$fach['Code'].' >'.$fach['Code'].'</option>';
			}
		}
		?>
	</select><br />
	
<label for="Kurs">Kursfilter: </label>
	<select onchange="setKurs(this.selectedIndex,'<?php echo $selectedfach ?>')">
		<?php
		if($selectedkurs == 'Alle')
		{
			echo '<option value="Alle" selected>Alle</option>';
		}
		else 
		{
			echo '<option value="Alle">Alle</option>';
		}
		
		foreach ($kurse as $kurs){
			if($selectedkurs == $kurs['Code'])
			{
				echo '<option value='.$kurs['Code'].' selected >'.$kurs['Code'].'</option>';
			}
			else 
			{
				echo '<option value='.$kurs['Code'].' >'.$kurs['Code'].'</option>';
			}
		}
		?>
	</select><br />

<table class="tablesorter" cellspacing="1">
	<thead>
	    <tr>
	      <th>ID</th>
	      <th>Beschreibung</th>
	      <th>Fach</th>
	      <th>Anzahl Fragen</th>
	      <th>Kurs</th>
	      <th>Noten Code</th>
	      <th>Freigabe</th>
	      <th>Bearbeiten</th>
	      <th> Fragen Zuordnen</th>
	      <th>Korrigieren</th>
	      <th>Zeige Teilnehmer</th>      
	    </tr>
  	</thead>
	<tbody >
		<?php foreach ($klausuren as $row): ?>
	    <tr>
	        <td><?php echo $row['ID'];?></td>
	        <td><?php echo $row['Beschreibung'];?></td>
	        <td><?php echo $row['Fach'];?></td>
	        <td><?php echo $row['AnzahlFragen'];?></td>
	        <td><?php echo $row['KurseCode'];?></td>
	        <td><?php echo $row['NotenCode'];?></td>
	        <td><?php echo $row['Freigabe'];?></td>
	        <td>
		        <?php $this->load->helper(array('form')); ?>
		    	<?php echo validation_errors(); ?>
				<?php echo form_open('klausuren_controller/validate_view')?>
				<input type="input" name="klausurenid" hidden="true" value=<?php echo $row['ID'];?>  />			
	        	<input class="art-button" type='submit' name='submit' value='Ändern' > 	       
	        </form>   
	        </td>
	        <td>
	        	<?php $this->load->helper(array('form')); ?>
		    	<?php echo validation_errors(); ?>
				<?php echo form_open('klausurenfragen_controller/klausurenfragenlistview/0/'.$selectedfach)?>
				<input type="input" name="klausurenid" hidden="true" value=<?php echo $row['ID'];?>  />
				<input type="input" name="anzahlfragen" hidden="true" value=<?php echo $row['AnzahlFragen'];?>  />
	        	<input class="art-button" type='submit' name='submit' value='Fragen zuordnen' > 
	        </form>   
	        </td>
	 		<td>
	 			<?php echo validation_errors(); ?>
				<?php echo form_open('klausurenfragen_controller/correctclasstest')?>
				<input type="input" name="klausurenid" hidden="true" value=<?php echo $row['ID'];?>  />
	 			<input class="art-button" type='submit' name='submit' value='Korrigieren' > 
	 		</form>  
	 		</td>   
	 		<td>
	 			<?php echo validation_errors(); ?>
				<?php echo form_open('kurseteilnehmer_controller/classtestuserresult')?>
				<input type="input" name="klausurenid" hidden="true" value=<?php echo $row['ID'];?>  />
	 			<input type="input" name="kursecode" hidden="true" value=<?php echo $row['KurseCode'];?>  />
	 			<input class="art-button" type='submit' name='submit' value='Zeige Teilnehmer' > 
	 		</form> 
	 		</td>
	    </tr>
		<?php endforeach; ?>
	</tbody>
</table>
<?php for($i = 0; $i < $pages; $i++): ?>
<?php 
    $j = $i+1;
    echo anchor('klausuren_controller/klausurenlistview/'.$i.'/'.$selectedfach.'/'.$selectedkurs, ''.$j, 'class="link-class"') 
?> &nbsp;
<?php endfor ?>

<?php $this->load->helper(array('form')); ?>
<?php echo validation_errors(); ?>
<?php echo form_open('klausuren_controller/create_view')?>
<input class="art-button" type='submit' name='submit' value='Neue Klausur' >

<div id="pager" class="pager">
	<form>
		<img src="../addons/pager/icons/first.png" class="first"/>
		<img src="../addons/pager/icons/prev.png" class="prev"/>
		<input type="text" class="pagedisplay"/>
		<img src="../addons/pager/icons/next.png" class="next"/>
		<img src="../addons/pager/icons/last.png" class="last"/>
		<select class="pagesize">
			<option selected="selected"  value="10">10</option>
			<option value="20">20</option>
			<option value="30">30</option>
			<option  value="40">40</option>
		</select>
	</form>
</div>
<script>
$(document).ready(function() 
    { 
        $("table").tablesorter({ 
        // pass the headers argument and assing a object 
        headers: { 
            // assign the secound column (we start counting zero) 
            7: { 
                // disable it by setting the property sorter to false 
                sorter: false 
            }, 
            // assign the third column (we start counting zero) 
            8: { 
                // disable it by setting the property sorter to false 
                sorter: false 
            }, 
            9: { 
                // disable it by setting the property sorter to false 
                sorter: false 
            },
            10: { 
                // disable it by setting the property sorter to false 
                sorter: false 
            }
        },
        widthFixed: true, 
        widgets: ['zebra'] 
    })
    .tablesorterPager({container: $("#pager")});
    
    
    
    } 
); 
</script>